home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Monster Media 1996 #14
/
Monster Media No. 14 (April 1996) (Monster Media, Inc.).ISO
/
prog_d
/
mdexp12.zip
/
MAIN.PAS
< prev
next >
Wrap
Pascal/Delphi Source File
|
1996-01-03
|
12KB
|
402 lines
unit Main;
interface
uses
SysUtils, WinTypes, WinProcs, Messages, Classes, Graphics, Controls,
Forms, Dialogs, Connect, DBTables, DB, StdCtrls, Mask, DBCtrls, ExtCtrls,
Buttons, Grids, Outline, Mdexplor, DBGrids;
type
TDemoForm1 = class(TForm)
Panel3: TPanel;
Label2: TLabel;
Image1: TImage;
Panel4: TPanel;
SpeedButton1: TSpeedButton;
SpeedButton2: TSpeedButton;
SpeedButton3: TSpeedButton;
DBNavigator1: TDBNavigator;
Panel2: TPanel;
Label1: TLabel;
Panel5: TPanel;
Notebook1: TNotebook;
Label8: TLabel;
DBText1: TDBText;
Label5: TLabel;
DBEdit4: TDBEdit;
DBText2: TDBText;
Label9: TLabel;
Label10: TLabel;
Label6: TLabel;
DBEdit5: TDBEdit;
DBEdit7: TDBEdit;
DBText4: TDBText;
Label11: TLabel;
Label12: TLabel;
Label7: TLabel;
DBEdit6: TDBEdit;
DBEdit8: TDBEdit;
Label13: TLabel;
Label14: TLabel;
Label15: TLabel;
Label16: TLabel;
Label17: TLabel;
DBEdit3: TDBEdit;
DBEdit9: TDBEdit;
DBEdit10: TDBEdit;
DBEdit11: TDBEdit;
DBEdit12: TDBEdit;
Label3: TLabel;
Label4: TLabel;
Label18: TLabel;
DBText3: TDBText;
Label19: TLabel;
Label20: TLabel;
Label21: TLabel;
Label22: TLabel;
Label23: TLabel;
DBEdit1: TDBEdit;
DBEdit2: TDBEdit;
DBEdit13: TDBEdit;
DBEdit14: TDBEdit;
DBEdit15: TDBEdit;
DBEdit16: TDBEdit;
DBEdit17: TDBEdit;
Table1: TTable;
Table1Company: TStringField;
Table1CustNo: TFloatField;
DataSource1: TDataSource;
Table2: TTable;
Table2OrderNo: TFloatField;
Table2CustNo: TFloatField;
Table2PO: TStringField;
Table2AmountPaid: TCurrencyField;
Table2EmpNo: TIntegerField;
DataSource2: TDataSource;
Table4: TTable;
Table4ItemNo: TFloatField;
Table4Description: TStringField;
Table4OrderNo: TFloatField;
Table4Qty: TIntegerField;
Table4PartNo: TFloatField;
DataSource4: TDataSource;
Table3: TTable;
Table3VendorName: TStringField;
Table3PartNo: TFloatField;
Table3VendorNo: TFloatField;
Table3Description: TStringField;
Table3OnHand: TFloatField;
Table3OnOrder: TFloatField;
Table3Cost: TCurrencyField;
Table3ListPrice: TCurrencyField;
DataSource3: TDataSource;
Table5: TTable;
Table5VendorNo: TFloatField;
Table5VendorName: TStringField;
Table5Address1: TStringField;
Table5Address2: TStringField;
Table5City: TStringField;
Table5State: TStringField;
Table5Zip: TStringField;
Table5Country: TStringField;
Table5Phone: TStringField;
Table5FAX: TStringField;
Table5Preferred: TBooleanField;
DataSource5: TDataSource;
MDExplorer: TMDExplorer;
Connections1: TConnections;
ComboBox1: TComboBox;
Table6: TTable;
DataSource6: TDataSource;
Table7: TTable;
DataSource7: TDataSource;
Connections2: TConnections;
Table6VendorNo: TFloatField;
Table6VendorName: TStringField;
Table6City: TStringField;
Table6State: TStringField;
Table6Country: TStringField;
Table6Phone: TStringField;
Table7PartNo: TFloatField;
Table7VendorNo: TFloatField;
Table7Description: TStringField;
Table7OnHand: TFloatField;
Table7OnOrder: TFloatField;
Table7Cost: TCurrencyField;
Table7ListPrice: TCurrencyField;
Table8: TTable;
DataSource8: TDataSource;
Connections3: TConnections;
Table8SpeciesNo: TFloatField;
Table8Common_Name: TStringField;
DBImage1: TDBImage;
Table8Graphic: TGraphicField;
Table8Notes: TMemoField;
DBMemo1: TDBMemo;
DBGrid1: TDBGrid;
Table9: TTable;
DataSource9: TDataSource;
Table9CustNo: TFloatField;
Table9Company: TStringField;
Table9Addr1: TStringField;
Table9Addr2: TStringField;
Table9City: TStringField;
Table9State: TStringField;
Table9Zip: TStringField;
Table9Country: TStringField;
Table9Phone: TStringField;
Table9FAX: TStringField;
Table9TaxRate: TFloatField;
Table9Contact: TStringField;
Table9LastInvoiceDate: TDateTimeField;
Connections4: TConnections;
procedure SpeedButton1Click(Sender: TObject);
procedure SpeedButton2Click(Sender: TObject);
procedure SpeedButton3Click(Sender: TObject);
procedure FormCreate(Sender: TObject);
procedure MDExplorerUpdating(Sender: TObject; Updating: Boolean);
procedure MDExplorerClick(Sender: TObject);
procedure Table4DescriptionGetText(Sender: TField;
var Text: OpenString; DisplayText: Boolean);
procedure Table3VendorNameGetText(Sender: TField; var Text: OpenString;
DisplayText: Boolean);
procedure ComboBox1Change(Sender: TObject);
procedure DataSource9DataChange(Sender: TObject; Field: TField);
private
{ Private declarations }
public
{ Public declarations }
end;
var
DemoForm1: TDemoForm1;
implementation
{$R *.DFM}
{ Plus SpeedButton ------------------------------------}
procedure TDemoForm1.SpeedButton1Click(Sender: TObject);
begin
{ Expand the current node }
with MDExplorer do
begin
Items[SelectedItem].Expand;
end;
end;
{ Minus SpeedButton ----------------------------------}
procedure TDemoForm1.SpeedButton2Click(Sender: TObject);
begin
{ Collapse the current node }
with MDExplorer do
begin
Items[SelectedItem].Collapse;
end;
end;
{ Edit SpeedButton ----------------------------------}
procedure TDemoForm1.SpeedButton3Click(Sender: TObject);
begin
{ Hide/show the editing panel at bottom}
if Panel5.Visible then
begin
Panel5.Visible := False;
SpeedButton3.Down := False;
end
else
begin
Panel5.Visible := True;
SpeedButton3.Down := True;
end;
end;
{ Form Creation -------------------------------}
procedure TDemoForm1.FormCreate(Sender: TObject);
begin
{ Activate all datasources before activating
the TMDExplorer component. }
Table1.Active := True;
Table2.Active := True;
Table4.Active := True;
Table3.Active := True;
Table5.Active := True;
Table6.Active := True;
Table7.Active := True;
Table8.Active := True;
Table9.Active := True;
Combobox1.ItemIndex := 0; { Initialize ComboBox }
MDExplorer.Active := True; { Activate TMDExplorer }
end;
{ TMDExplorer updating event handler ---------------------------}
procedure TDemoForm1.MDExplorerUpdating(Sender: TObject;
Updating: Boolean);
begin
{ Some data-aware components slow down outline processing
if they are connected to the data model while the outline
is updating. Disconnect them from the data model while
the outline is updating by setting their DataSource to nil.
Do NOT use DisableControls because this also disconnects
datasouces from the master-detail model. TDBGrids should be
on a seperate model from TMDExplorer. In this case DBGrid1
is in the Grid Model and the MDOutline1 is in the Customers
Model. Synchronize two such data models with SyncTables.
SyncTables requires that both TTables be connected to the
same physical table, and that the two TTables use the same
index (Sequence numbers are used to prevent update
recursion.) }
if Updating then { Begin updating TMDExplorer }
begin
{ Disconnect any data-aware components here if they slow
down processing.}
DBImage1.DataSource := nil;
DBMemo1.DataSource := nil;
end
else {End updating TMDExplorer }
begin
{ Re-connect slow data-aware components here }
DBImage1.DataSource := DataSource8;
DBMemo1.DataSource := Datasource8;
{ This ensures that changes in the Explorer are reflected
in the Grid. Disconnecting the grid by setting its
datasource to nil will cause a flash.
See DataSource9.OnDataChange event for more details.}
SyncTables(Table9,Table1); { Move Table9 (Grid) to match Table1 (Explorer) }
{ For this demo, we set the notebook's page index to display
the current level's edit controls, and we set the navigator
to navigate the current level's datasource. Levels begin
at one, pages at zero.}
Notebook1.PageIndex := MDExplorer.CurrentLevel-1;
DBNavigator1.DataSource := MDExplorer.CurrentDataSource;
end;
end;
{ TMDExplorer Click event handler -------------------------}
procedure TDemoForm1.MDExplorerClick(Sender: TObject);
begin
{ Set the notebook page to display the current level's edit
controls, and set the navigator to navigate the current
level's datasource.}
Notebook1.PageIndex := MDExplorer.CurrentLevel-1;
DBNavigator1.DataSource := MDExplorer.CurrentDataSource;
end;
{**************************************************************}
{* The OnCalcFields event does not seem to work correctly with*}
{* the TMDExplorer. Instead, use each field's GetText method *}
{* for calculated fields. This MAY be a bug in Delphi. *}
{**************************************************************}
{ Calculate part description for ITEMS level --------------}
procedure TDemoForm1.Table4DescriptionGetText(Sender: TField;
var Text: OpenString; DisplayText: Boolean);
begin
{ Table4=ITEMS, Table3=PARTS, ITEMS >---|- PARTS }
{ Move PARTS Description up one level to ITEMS level.}
Text := Table3Description.AsString;
end;
{ Calculate vendor name for PARTS level -----------------}
procedure TDemoForm1.Table3VendorNameGetText(Sender: TField;
var Text: OpenString; DisplayText: Boolean);
begin
{ Table3=PARTS, Table5=VENDORS, PARTS >---|- VENDORS }
{ Move VENDORS VendorName up one level to PARTS level.}
Text := Table5VendorName.AsString;
end;
{ ComboBox event handler to change views ------------}
procedure TDemoForm1.ComboBox1Change(Sender: TObject);
begin
{ Change views by dynamically changing the TMDExplorer
DataSources. Make TMDExplorer inactive before making
such changes.}
case ComboBox1.ITemIndex of
0: { Customers View }
begin
{ Enable editing for Customers view}
SpeedButton3.Visible := True;
if SpeedButton3.Down then Panel5.Visible := True;
DBImage1.Visible := False;
DBMemo1.Visible := False;
MDExplorer.Active := False;
MDExplorer.DataSource1 := DataSource1; {CUSTOMER}
MDExplorer.DataSource2 := DataSource2; {ORDERS}
MDExplorer.DataSource3 := DataSource4; {ITEMS}
MDExplorer.DataSource4 := DataSource3; {PARTS}
MDExplorer.DataSource5 := DataSource5; {VENDORS}
MDExplorer.Active := True;
end;
1: { Vendors View }
begin
{ Disable editing for Vendors view for simplicity }
SpeedButton3.Visible := False;
Panel5.Visible := False;
DBImage1.Visible := False;
DBMemo1.Visible := False;
MDExplorer.Active := False;
MDExplorer.DataSource1 := DataSource6; {VENDORS}
MDExplorer.DataSource2 := DataSource7; {PARTS}
MDExplorer.DataSource3 := nil;
MDExplorer.DataSource4 := nil;
MDExplorer.DataSource5 := nil;
MDExplorer.Active := True;
end;
2: { Fish View }
begin
{ Disable editing for Fish view for simplicity }
SpeedButton3.Visible := False;
Panel5.Visible := False;
DBImage1.Visible := True;
DBMemo1.Visible := True;
MDExplorer.Active := False;
MDExplorer.DataSource1 := DataSource8; {BIOLIFE}
MDExplorer.DataSource2 := nil;
MDExplorer.DataSource3 := nil;
MDExplorer.DataSource4 := nil;
MDExplorer.DataSource5 := nil;
MDExplorer.Active := True;
end;
end;
end;
procedure TDemoForm1.DataSource9DataChange(Sender: TObject; Field: TField);
begin
{ Synchronize the Grid Model with the Customers Model. This
is necessary for changes in the grid to be reflected in
the Explorer. SyncTables is provided for this purpose.
A TMDExplorer cannot be connected to the same data model
as a DBGrid because there is no way to make the DBGrid
not update as the TMDExplorer updates. DisableControls
will disconnect the Master-Detail datasources from one
another, and any other trick makes the grid flash badly.}
SyncTables(Table1,Table9); { Move Table1 to match Table9. }
end;
end.